package com.xxgc.spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class VideoController {

    @RequestMapping("/video/{videoUrl}/{userId}")
    public String playViedo(@PathVariable("userId") String userId,
                            @PathVariable("videoUrl") String videoUrl,
                            @RequestParam(value = "spm_id_from", required = false) String money) {
        System.out.println("userId = " + userId);
        System.out.println("videoUrl = " + videoUrl);
        System.out.println("money = " + money);

        //如果为空就返回默认欢迎页面
        return "redirect:https://www.bilibili.com/video/" + videoUrl + "?spm_id_from=" + money;
    }

    @RequestMapping("/video/getVideoUrl")
    @ResponseBody
    public String routeTime(Date time) {
        //Spring MVC自带的类型转换器
        //获取的请求时间 1636964402000
        System.out.println("time = " + time.getTime());
        //获取当前系统时间
        long nowTime = new Date().getTime();
        System.out.println("nowTime = " + nowTime);
        //当前系统时间 - 用传过来的时间
        int routeTime = (int) (nowTime - time.getTime());

        return "请求路由耗时"+routeTime + "毫秒";
    }
}
